home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Eagles Nest BBS 8
/
Eagles_Nest_Mac_Collection_Disc_8.TOAST
/
Developer Tools⁄Additions
/
InsideBa1994
/
InsideBasic-94
/
IB 94
/
Alpha Dollars
/
Alpha Dollars (Z)
Wrap
Text File
|
1991-11-21
|
6KB
|
177 lines
' | =======================================================================
' |
' | -- Function Alpha Dollars -- By Jerry W. Guy (JGUY@Pro-Finders.CTS.COM)
' | 201 Randomwood Lane
' | New Bern, NC 28562
' | FN Alpha$(AD_Value$)
' |
' | This function is used to convert a numeric value to the equivelant
' | value in words. The returned string is in the same format used to
' | printout a check amount or a fee in a legal contract. The digits to
' | the right of 2 places are truncated not rounded up. 12.349 = 12.340
' |
' | 343.23 = "Three Hundred Forty Three and 23/100 Dollars"
' |
' | To use this function
' | Just plug your dollar value into the STRING passed to the function
' |
' | Check_string$ = FN Alpha$(STR$(123456.89))
' |
' | * * * The value MUST NOT be greater than the Quadrillions (1E+19) * * *
' |
LONG FN Alpha$(AD_Value$)
' |
' | Initialize a few variables
' | The AD_Position% variable is used to offset into the words to get
' | hundreds, thousands, etc..
' | the 28th entry is Hundred
AD_Position% = 28
AD_Return$ = ""
' |
' | Do a range check on the VAL of the string to prevent out of bounds
' | subscripting etc..
' |
WHILE VAL(AD_Value$) > 0 AND VAL(AD_Value$) < 1E+19
' |
' | If this is the first time the function is called load up the
' | AD_Words$ table with the appropriate values
' |
LONG IF AD_1sttime% = 0
DATA One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten
DATA Eleven, Twelve, Thirteen, Fourteen, Fifteen, Sixteen, Seventeen
DATA Eighteen, Nineteen, Twenty, Thirty, Forty, Fifty, Sixty, Seventy
DATA Eighty, Ninety, Hundred,Thousand, Million, Billion, Trillion
DATA Quadrillion
DIM 18 AD_Words$(33)
FOR AD_1sttime% = 1 TO 33
READ AD_Words$(AD_1sttime%)
NEXT AD_1sttime%
END IF
' |
' | Dealing with a sting instead of a numeric value means being careful!
' | Check for Comma's in the input string and get em out.
' |
WHILE INSTR(1,AD_Value$,",")
ADH_Temp$ = ""
FOR AD_Index% = 1 TO LEN(AD_Value$)
LONG IF MID$(AD_Value$,AD_Index%,1) <> ","
ADH_Temp$ = ADH_Temp$ + MID$(AD_Value$,AD_Index%,1)
END IF
NEXT AD_Index%
AD_Value$ = ADH_Temp$
WEND
' |
' | We Have to get the cents out of the string and watch
' | for assumed 00 assumed 0 after single digit and too
' | many digits after the decimal point
' |
' | Kludge around numbers longer than 12 digits!
' |
AD_Cents$ = MID$( STR$ (FRAC (VAL (RIGHT$(AD_Value$,10)))),3,2)
' |
' | If we have a blank string put in the zeros
' |
IF LEN(AD_Cents$) = 0 THEN AD_Cents$ = "00"
' |
' | if we have a short string add a trailing zero
' |
IF LEN(AD_Cents$) = 1 THEN AD_Cents$ = AD_Cents$ + "0"
' |
' | OK Now we got the pennies straight in AD_Cents$ lets get to the
' | Big numbers starting from the right working up the amount string.
' |
' | Get the whole dollars to play with.
' |
AD_Decimal% = INSTR(1,AD_Value$,".")
AD_Whole$ = LEFT$(AD_Value$,AD_Decimal%-1)
' |
' | This is the main process of the program. It takes a hunk of
' | 3 characters starting from the right of the whole number and
' | builds a sting with it
' |
ADH_Temp$ = ""
WHILE LEN(AD_Whole$) > 0
AD_Whole_Value$ = RIGHT$(AD_Whole$,3)
LONG IF VAL(AD_Whole_Value$) > 0
LONG IF VAL(AD_Whole_Value$) > 99
ADH_Temp$ = AD_Words$( VAL (LEFT$ (AD_Whole_Value$,1)))
ADH_Temp$ = ADH_Temp$ + " " + AD_Words$(28)
END IF
AD_Whole_Value$ = RIGHT$(AD_Whole_Value$,2)
LONG IF VAL(AD_Whole_Value$) > 0
LONG IF VAL(AD_Whole_Value$) > 20
ADH_Temp$ = ADH_Temp$ + " " + AD_Words$(VAL(LEFT$(AD_Whole_Value$,1))+18)
LONG IF VAL(MID$(AD_Whole_Value$,2,1)) > 0
ADH_Temp$ = ADH_Temp$ + "-"
AD_Lcase$ = AD_Words$(VAL(RIGHT$(AD_Whole_Value$,1)))
POKE VARPTR(AD_Lcase$)+1,PEEK(VARPTR(AD_Lcase$)+1)+32
' | HUH??
' | The Poke and peek here are to convert the firts digit of the
' | number after the dash to lower case.
' |
ADH_Temp$ = ADH_Temp$ + AD_Lcase$
END IF
XELSE
ADH_Temp$ = ADH_Temp$ + " " + AD_Words$(VAL(AD_Whole_Value$))
END IF
END IF
LONG IF AD_Position% > 28
ADH_Temp$ = ADH_Temp$ + " " + AD_Words$(AD_Position%)
END IF
AD_Return$ = ADH_Temp$ + " " + AD_Return$
END IF
' |
' | Move the position multiplier to the next range
' |
AD_Position% = AD_Position% + 1
' |
' | If there are less than 3 characters in the string were done
' |
LONG IF LEN(AD_Whole$) > 3
AD_Whole$ = LEFT$(AD_Whole$,LEN(AD_Whole$)-3)
XELSE
AD_Whole$ = ""
END IF
' |
' | The next check is to fix an extra space that would show up in
' | the string
' |
LONG IF LEFT$(AD_Return$,1) = " "
AD_Return$ = MID$(AD_Return$,2,LEN(AD_Return$))
END IF
ADH_Temp$ = ""
WEND
' | ^
' | End of the main program logic. Now we should have a value string in
' | AD_Return$.
' |
' |
AD_Value$ = ""
WEND
' |
' | End of when the value is in range
' |
LONG IF LEN(AD_Return$)
AD_Return$ = AD_Return$ + "and " + AD_Cents$ + "/100 Dollars"
XELSE
AD_Return$ = "Error!"
END IF
END FN = AD_Return$ ' End of Alpha$ Function
'
' That's all folks the following lines test out the function.
'
"begin"
DO
INPUT "Enter a # between 1 and 999999999999999999 (no commas) -> ";VALUE$
PRINT FN Alpha$(VALUE$)
UNTIL VALUE$ = ""